// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CodeCleanupSettingsManager.cs" company="Roman '4ux-nbIx' Novitsky">
//   Copyright (c) Roman '4ux-nbIx' Novitsky 2009
// </copyright>
// <summary>
//   Defines the CodeCleanupSettingsManager type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace SettingsManager.ComponentSettingsManagers
{
  #region Namespace Imports

  using System.Collections.Generic;
  using System.Xml;

  using JetBrains.ComponentModel;
  using JetBrains.ReSharper.Feature.Services.CodeCleanup;

  #endregion


  /// <summary>
  /// Describes and manipulates the code cleanup component settings manager.
  /// </summary>
  internal sealed class CodeCleanupSettingsManager : ResharperComponentSettingsManager
  {
    #region Constructors and Destructors

    /// <summary>
    /// Initializes a new instance of the <see cref="CodeCleanupSettingsManager"/> class.
    /// </summary>
    public CodeCleanupSettingsManager()
      : base("CodeCleanup", "Code Cleanup Settings")
    {
    }

    #endregion


    #region Public Methods

    /// <summary>
    /// Loads the settings.
    /// </summary>
    /// <param name="component">
    ///   The component.
    /// </param>
    /// <param name="element">
    ///   The element.
    /// </param>
    /// <param name="options"></param>
    public override void LoadSettings(IXmlExternalizableComponent component, XmlElement element, object options)
    {
      var codeCleanup = component as CodeCleanup;

      if (codeCleanup == null)
      {
        return;
      }

      ICollection<CodeCleanupProfile> cleanupProfiles = codeCleanup.Profiles;
      var profilesToRemove = new List<CodeCleanupProfile>();

      foreach (CodeCleanupProfile profile in cleanupProfiles)
      {
        if (!profile.IsDefault)
        {
          profilesToRemove.Add(profile);
        }
      }

      foreach (CodeCleanupProfile profile in profilesToRemove)
      {
        cleanupProfiles.Remove(profile);
      }

      codeCleanup.Profiles = cleanupProfiles;

      base.LoadSettings(component, element, options);
    }

    #endregion
  }
}